// import Vue from 'vue';
import { Notify } from 'vant';
import axios from 'axios'
// Vue.use(Notify);

axios.defaults.baseURL = 'http://127.0.0.1:8888';

// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';


axios.interceptors.request.use(function (config) {
  let token = localStorage.getItem("token");
  config.headers.token = token ?? '';
  return config;
}, function (error) {
  return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
  let data = response.data;

  if (data?.code !== 200) {
    Notify({ type: 'warning', message: data.message })
  }

  if (data.code === 401) {
    setTimeout(`window.location.href = " /accoun/login"`, 1000)
  }

  return data;
}, function (error) {
  Notify({ type: 'danger', message: "报错喽" })
  return Promise.reject(error);
});

export default axios
